<?php
require_once('../practice/db.php');

pr($_POST);
pr($_FILES);

$id = $_POST['id'];
$last_path  = $_POST['last_path'];

$data['title'] = $_POST['title'];
$data['uploaded_date'] = date('Y-m-d H:i:s');



if($_FILES['path']['error'] == 0) {

  $file_name = date('ymdHis').'_'.rand().'_'.$_FILES['path']['name'];
  $source = $_FILES['path']['tmp_name'];
  $dest = "uploads/$file_name";

  $isUploaded = move_uploaded_file($source, $dest);

  //Delete Old One
  unlink("uploads/$last_path");

  if($isUploaded == true){

    $data['path'] = $file_name;

  } else {
    echo "<h1>Your Bad !!</h1>";
  }
}
    ////////////////////////////////
    update('uploaded_images', $data," WHERE `id`='$id'");
    ////////////////////////////////
    echo "<h1>Congrats !! you have successfully uploaded one filee.</h1>";




//else {
  //echo "<h4>Something went wrong!! :( </h4>";
//}

header('location:show_all_images.php');
